package test_unitaire;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import junit.framework.TestCase;

import org.junit.After;
import org.junit.Test;

import buisness_service.Common_methods;
import buisness_service.Depense;
import buisness_service.Rapport;
import buisness_service.Revenu;
import buisness_service.User;

public class Test_common_methods extends TestCase {

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testSommeTotalDepenses() {

		Calendar d = Calendar.getInstance();
		d.set(2009, Calendar.DECEMBER, 12);
		User u = new User();
		Depense dep = new Depense(20, d, u);
		Depense dep2 = new Depense(40, d, u);
		List<Depense> listDepense = new ArrayList<Depense>();
		listDepense.add(dep2);
		listDepense.add(dep);
		assertTrue(Common_methods.SommeTotalDepenses(listDepense) == 60);
		assertTrue(Common_methods.Epargne(listDepense, u.getRevenus()) == -60);
		
		Rapport.postesDpenses.clear();
		Rapport.postesRevenus.clear();
	}

	@Test
	public void testSommeTotalRevenus() {

		Calendar d = Calendar.getInstance();
		d.set(2009, Calendar.DECEMBER, 12);
		User u = new User();
		Revenu rev = new Revenu(20, d, u);
		Revenu rev2 = new Revenu(40, d, u);
		List<Revenu> listRevenu = new ArrayList<Revenu>();
		listRevenu.add(rev2);
		listRevenu.add(rev);
		assertTrue(Common_methods.SommeTotalRevenus(listRevenu) == 60);
		assertTrue(Common_methods.Epargne(u.getDepenses(), listRevenu) == 60);
		
		Rapport.postesDpenses.clear();
		Rapport.postesRevenus.clear();
	}

	@Test
	public void testEpargne() {

		Calendar d = Calendar.getInstance();
		d.set(2009, Calendar.DECEMBER, 12);
		User u = new User();
		Depense dep = new Depense(20, d, u);
		Depense dep2 = new Depense(40, d, u);
		List<Depense> listDepense = new ArrayList<Depense>();
		listDepense.add(dep2);
		listDepense.add(dep);
		u.setDepenses(listDepense);
		Revenu rev = new Revenu(25, d, u);
		Revenu rev2 = new Revenu(50, d, u);
		List<Revenu> listRevenu = new ArrayList<Revenu>();
		listRevenu.add(rev2);
		listRevenu.add(rev);
		u.setRevenus(listRevenu);
		assertTrue(Common_methods.Epargne(u.getDepenses(), u.getRevenus()) == 15);
		
		Rapport.postesDpenses.clear();
		Rapport.postesRevenus.clear();
	}

}
